/***************************************************************************************************
*  File Name   : DataStruct_FrameWork_Proc.c                                                       *
*  Version No  : Ver 005                                                                           *
*  Description : This Source File include Interface Function for operating different kind of List  *
*  Author      : Tianyufang                                                                        *
*  Copyright   : Copyright (c) Tianyufang(personal).All Rights Reserved                            *
*  Creat Date  : 2012/11/06                                                                        *
*  Modify Date : 2012/11/09                                                                        *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/09/23  New                                                                 *
*  2   Tianyufang  2012/10/30  Fixed  wubSlgLnkedListDeleteNode                                    *
*  3   Tianyufang  2012/11/05  Add    wvdLinkedListInitProc                                        *
*                  2012/11/06  Rename All Function Name (Lnked->Linked)                            *
*                              Sample: wubSlgLnkedListCreatNode -> wubSlgLinkedListCreatNode       *
*                  2012/11/06  Fixed  All Function                                                 *
*  4   Tianyufang  2012/11/10  Rename pstDSFRootNode -> pstDSFSglRootNode                          *
*                                     pstDSFLastNode -> pstDSFSglLastNode                          *
*                                   wuiDSFNodeNo -> [DSF_LINKED_LIST_TYPE_MAX][DSF_LINKED_LIST_MAX]*
*                     wuiDSFNodeNum -> wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_MAX][DSF_LINKED_LIST_MAX]*
*                                wuwDSFLinkedListNo -> wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_MAX]*
*  5   Tianyufang  2012/11/09  Fixed wvdLinkedListSetNoProc                                        *
*  6   Tianyufang  2012/11/12  Fixed wubSglLinkedListInitProc                                      *
*                                                                                                  *
*==================================================================================================*/

/*=================================================================================================*
*                                          Include Files                                           *
**=================================================================================================*/
#include "compiler_switch_def.h"
#include "TypeDef.h"
#include "common_stdlib.h"

#include "DataStructFramework_Var.h"
#include "DataStructFramework_Proc.h"

#include "../Appli/DataStructFramework_UserDefine.h"
/*=================================================================================================*
*                                          Section Define                                          *
**=================================================================================================*/

/*=================================================================================================*
*                                          Macro Define                                            *
**=================================================================================================*/

/*=================================================================================================*
*                                          Struct Define                                           *
**=================================================================================================*/

/*=================================================================================================*
*                                          Globle Variable                                         *
**=================================================================================================*/

/*=================================================================================================*
*                                          Function Declaration                                    *
**=================================================================================================*/

/***************************************************************************************************
*  Function Name : wvdLinkedListSetNoProc                                                          *
*  Version No    : Ver 002                                                                         *
*  Description   : Choose which linked list user want to operate                                   *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/11/05                                                                      *
*  Modify Date   : 2012/11/05                                                                      *
*  Parament      : uWord ListNo       : linked list No that user define                            *
*                  uByte ListType     : linked list type that user define                          *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/11/05  New                                                                 *
*  2   Tianyufang  2012/11/09  All Para ListType and Judge for ListType                            *
*                                                                                                  *
*==================================================================================================*/
uByte wvdLinkedListSetNoProc(uWord ListNo, uByte ListType)							/* 2012/11/09 Fixed by Tianyufang */
{
	uByte aubRslt;

	aubRslt = DSF_OPRT_NG;
	
	if ((ListNo < DSF_LINKED_LIST_MAX) && (ListType < DSF_LINKED_LIST_TYPE_MAX))	/* 2012/11/09 Fixed by Tianyufang */
	{
		wuwDSFLinkedListNo[ListType]	=	ListNo;									/* 2012/11/09 Fixed by Tianyufang */
		aubRslt							=	DSF_OPRT_OK;
	}

	return aubRslt;
}

#ifdef SINGLY_LINKED_LIST
/***************************************************************************************************
*  Function Name : wvdSglLinkedListInitProc                                                        *
*  Version No    : Ver 002                                                                         *
*  Description   : Initialize Global Variables(DSF and user define) Process Function               *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/09/23                                                                      *
*  Modify Date   : 2012/11/12                                                                      *
*  Parament      : void(*pfUserInitProc)(void)           :initialize process for user define       *
*                : uWord ListNo                          :linked list No                           *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/09/25  New                                                                 *
*  2   Tianyufang  2012/11/05  Add Parameter(ListNo) and Process about ListNo                      *
*  3   Tianyufang  2012/11/09  Add Function Para DSF_LINKED_LIST_TYPE_SINGLE                       *
*  4   Tianyufang  2012/11/12  Add Return Value                                                    *
*                                                                                                  *
*==================================================================================================*/
uByte wubSglLinkedListInitProc(void (*pfUserInitProc)(void), uWord ListNo)
{
	uByte aubRslt;																		/* 2012/11/05 Fixed by Tianyufang */

	aubRslt = DSF_OPRT_NG;
	
	if (DSF_OPRT_OK == wvdLinkedListSetNoProc(ListNo, DSF_LINKED_LIST_TYPE_SINGLE))		/* Assigned Which Linked List user want to initlize */	/* 2012/11/09 Fixed by Tianyufang */
	{
		wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]	=	0;
		wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]	=	0;
		pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]	=	NULL;
		pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]	=	NULL;	/* 2012/11/05 Fixed by Tianyufang */

#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tDSF Var Init Finished\t");
#endif
	
		if (NULL != pfUserInitProc)														/* execute user initlize function */
		{
			(void)(*pfUserInitProc)();
			aubRslt = DSF_OPRT_OK;														/* 2012/11/12 Fixed by Tianyufang */
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tUser Var Init Finished\t");
#endif
		}
	}
	else
	{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tDSF Linked List Initlized out of range\t");
#endif
	}

	return aubRslt;																		/* 2012/11/12 Fixed by Tianyufang */
}

/***************************************************************************************************
*  Function Name : wubSglLinkedListCreatNode                                                       *
*  Version No    : Ver 002                                                                         *
*  Description   : Creat Linked List Node and allocate the memory for node                         *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/10/08                                                                      *
*  Modify Date   : 2012/11/06                                                                      *
*  Parament      : DSF_USERDEF_LIST_DATA **             : point of user defined data type          *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/09/25  New                                                                 *
*  2   Tianyufang  2012/11/06  Change Globle variables to array                                    *
*  3   Tianyufang  2013/01/09  Modify wuiDSFNodeNum increase process when memory alloc success     *
*                                                                                                  *
*==================================================================================================*/
uByte wubSglLinkedListCreatNode(DSF_USERDEF_LIST_DATA **pstDSFNode)
{
	wstSglLinkedList *apstDSFTempNode;
	uByte aubRslt;
	
	apstDSFTempNode = NULL;									/* local variables initlize */
	aubRslt = DSF_OPRT_NG;
	
	wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]++;				/* Node No increased */	/* 2012/11/06 Fixed by Tianyufang */
	apstDSFTempNode						=	(wstSglLinkedList *)MEM_ALLOC(sizeof(wstSglLinkedList));			/* alloc memory for point of Node */
	apstDSFTempNode->vpDataContainer	=	(DSF_USERDEF_LIST_DATA *)MEM_ALLOC(sizeof(DSF_USERDEF_LIST_DATA));	/* alloc memory for point of user data */
	apstDSFTempNode->uiListNo			=	wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];												/* 2012/11/06 Fixed by Tianyufang */

	if ((NULL != apstDSFTempNode) && (NULL != apstDSFTempNode->vpDataContainer))								/* make sure that memory alloc successed */
	{
		wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]++;			/* Node Num increased *//* 2013/01/09 Fixed by Tianyufang *//* 2012/11/06 Fixed by Tianyufang */
		pstDSFNode = (DSF_USERDEF_LIST_DATA **)apstDSFTempNode->vpDataContainer;								/* return user data address */
		memset(pstDSFNode, 0x00, sizeof(DSF_USERDEF_LIST_DATA));
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tCurrent Node Created,Address: 0x%08X,No:[%d]", apstDSFTempNode, wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]);	/* 2012/11/06 Fixed by Tianyufang */
#endif
		if ((uInt)(1) == wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]])																/* 2012/11/06 Fixed by Tianyufang */
		{
			pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] = apstDSFTempNode;																					/* Root node created */	/* 2012/11/06 Fixed by Tianyufang */
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tRoot Node Created,Address: 0x%08X,No:[%d]\t", pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]], wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]);		/* 2012/11/06 Fixed by Tianyufang */
#endif
		}
		else
		{
			pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]->pstNext = apstDSFTempNode;		/* more that one node, node linked operate */	/* 2012/11/06 Fixed by Tianyufang */
		}
		pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] = apstDSFTempNode;					/* move point of last node */	/* 2012/11/06 Fixed by Tianyufang */
		aubRslt = DSF_OPRT_OK;
	}
	else
	{
		wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]--;			/* memory alloc for node failed, Node No decrease */	/* 2012/11/06 Fixed by Tianyufang */
	}

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wubSglLinkedListSeekNode                                                        *
*  Version No    : Ver 002                                                                         *
*  Description   : Seek Linked List Node return the address of this node                           *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/10/08                                                                      *
*  Modify Date   : 2012/11/06                                                                      *
*  Parament      : BOOL(*pfUserInitProc)(DSF_USERDEF_LIST_DATA *) : User define function for seek  *
*                : DSF_USERDEF_LIST_DATA **                       : point of user seeked Node      *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/10/09  New                                                                 *
*  2   Tianyufang  2012/11/06  Change Globle variables to array                                    *
*                                                                                                  *
*==================================================================================================*/
uByte wubSglLinkedListSeekNode(BOOL (*pfUserSeekProc)(DSF_USERDEF_LIST_DATA *), DSF_USERDEF_LIST_DATA **pstNodeData)
{
	wstSglLinkedList *apstTempNode;
	uByte aubRslt;

	aubRslt = DSF_OPRT_NG;											/* local variable initlize */
	apstTempNode = NULL;
	pstNodeData = (DSF_USERDEF_LIST_DATA **)NULL;

	if (NULL != pfUserSeekProc)										/* whether user defined function is available */
	{
		apstTempNode = pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];				/* seek for Root node */	/* 2012/11/06 Fixed by Tianyufang */
		do
		{
			if (NULL != pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]])				/* whether none node had been created */	/* 2012/11/06 Fixed by Tianyufang */
			{
				break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tNone Node Exited!");
#endif
			}

			if (TRUE == (*pfUserSeekProc)((DSF_USERDEF_LIST_DATA *)apstTempNode->vpDataContainer))		/* user seek data is found */
			{
				pstNodeData	=	(DSF_USERDEF_LIST_DATA **)apstTempNode->vpDataContainer;				/* return address that user request */
				aubRslt		=	DSF_OPRT_OK;
				break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Finished, This is %d node", apstTempNode->uiListNo);
#endif
			}
			else
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Continue, Now is %d Node!", apstTempNode->uiListNo);
#endif
				apstTempNode = apstTempNode->pstNext;													/* user request data does not match, node point is movd to next */
			}
		}while(NULL != apstTempNode);
	}

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wubSglLinkedListDeleteNode                                                      *
*  Version No    : Ver 003                                                                         *
*  Description   : Delete Linked List Node and Return Data of this node                            *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/10/08                                                                      *
*  Modify Date   : 2012/11/06                                                                      *
*  Parament      : BOOL(*pfUserInitProc)(DSF_USERDEF_LIST_DATA *) : User define function for seek  *
*                : DSF_USERDEF_LIST_DATA *                        : point of node data that delete *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/10/09  New                                                                 *
*  2   Tianyufang  2012/10/30  Fix Issue of Root Node and Last Node was delete,point to wrong area *
*  3   Tianyufang  2012/11/06  Change Globle variables to array                                    *
*                                                                                                  *
*==================================================================================================*/
uByte wubSglLinkedListDeleteNode(BOOL (*pfUserDelProc)(DSF_USERDEF_LIST_DATA *), DSF_USERDEF_LIST_DATA *pstNodeData)
{
	wstSglLinkedList *apstTempNode, *apstLastNode;
	uByte aubRslt;

	aubRslt	= DSF_OPRT_NG;												/* local variable initlize */
	apstTempNode	= NULL;
	apstLastNode	= NULL;
	
	if (NULL != pfUserDelProc)											/* whether user defined function is available */
	{
		apstTempNode = pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];				/* point of node for pointing to current node pointed to Root node */	/* 2012/11/06 Fixed by Tianyufang */
		apstLastNode = pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];				/* point of node for pointing to last node pointed to Root node */	/* 2012/11/06 Fixed by Tianyufang */

		do
		{
			if (NULL == pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]])				/* whether none node had been created */	/* 2012/11/06 Fixed by Tianyufang */
			{
				break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tNone Node Exited");
#endif
			}
			if (TRUE == (*pfUserDelProc)((DSF_USERDEF_LIST_DATA *)apstTempNode->vpDataContainer))		/* node that user want to delete is found */
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Finished, node [%d] was deleted", apstTempNode->uiListNo);
#endif
				/*---- Comment ----*/	/* 2012/10/30 Fixed by Tianyufang */
				/* the possibility of node's position that you want to delete was shown below 
				No	Node Number      Want to Delete Node   Root Node       Last Node       Node Total Number
				1	     1                 Root               NULL            NULL                0
				2        > 1               Root            Root->Next       Do Nothing          N - 1
				3        > 1               Last            Do Nothing      Node(Last)->Next     N - 1
				4        > 1               Middle          Do Nothing       Do Nothing          N - 1*/
				if (pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] == apstTempNode)		/* 2012/11/06 Fixed by Tianyufang */
				{
					if (NULL == apstTempNode->pstNext)						/* process for 1 */
					{
						pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] = NULL;			/* 2012/11/06 Fixed by Tianyufang */
						pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] = NULL;			/* 2012/11/06 Fixed by Tianyufang */
					}
					else													/* process for 2 */
					{
						pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] = apstTempNode->pstNext;			/* 2012/11/06 Fixed by Tianyufang */
					}
				}
				else if (pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] == apstTempNode)				/* process for 3 */	/* 2012/11/06 Fixed by Tianyufang */
				{
					pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] = apstLastNode;						/* 2012/11/06 Fixed by Tianyufang */
				}
				else														/* process for 4 */
				{
					apstLastNode->pstNext = apstTempNode->pstNext;
				}
				/* 2012/10/30 Fixed by Tianyufang */

				(void)memcpy(pstNodeData, apstTempNode->vpDataContainer, sizeof(DSF_USERDEF_LIST_DATA));	/* return data that will be deleted */
				FREE(apstTempNode->vpDataContainer);														/* release memory for data of current node */
				FREE(apstTempNode);																			/* release memory for node of current node */
				wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]--;														/* 2012/11/06 Fixed by Tianyufang */
				aubRslt	= DSF_OPRT_OK;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tDelete Finished, [%d] node(s) remains", wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]);			/* 2012/11/06 Fixed by Tianyufang */
#endif

				break;
			}
			else
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Continue, Now is %d Node!", apstTempNode->uiListNo);
#endif
				apstLastNode = apstTempNode;
				apstTempNode = apstTempNode->pstNext;
			}
		}while(NULL != apstTempNode);
	}

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wubSglLinkedListInsertNode                                                      *
*  Version No    : Ver 002                                                                         *
*  Description   : Insert Linked List Node and pass Data for this node                             *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/10/26                                                                      *
*  Modify Date   : 2012/11/06                                                                      *
*  Parament      : BOOL(*pfUserModProc)(DSF_USERDEF_LIST_DATA *)  : User define function for Seek  *
*                : DSF_USERDEF_LIST_DATA                          : node data for insert           *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/10/26  New                                                                 *
*  2   Tianyufang  2012/11/06  Change Globle variables to array                                    *
*                                                                                                  *
*==================================================================================================*/
uByte wubSlgLinkedListInsertNode(BOOL (*pfUserInsProc)(DSF_USERDEF_LIST_DATA *), DSF_USERDEF_LIST_DATA *pstNodeData)
{
	wstSglLinkedList *apstTempNode, *apstLastNode, *apstNodeData;
	uByte aubRslt;

	aubRslt	= DSF_OPRT_NG;												/* local variable initlize */
	apstTempNode	= NULL;
	apstLastNode	= NULL;
	apstNodeData	= NULL;
	
	if (NULL != pfUserInsProc)											/* whether user defined function is available */
	{
		apstTempNode = pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];				/* point of node for pointing to current node pointed to Root node */	/* 2012/11/06 Fixed by Tianyufang */
		apstLastNode = pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];				/* point of node for pointing to last node pointed to Root node */	/* 2012/11/06 Fixed by Tianyufang */

		do
		{
			if (NULL == pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]])				/* whether none node had been created */	/* 2012/11/06 Fixed by Tianyufang */
			{
				break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tNone Node Exited!");
#endif
			}
			if (TRUE == (*pfUserInsProc)((DSF_USERDEF_LIST_DATA *)apstTempNode->vpDataContainer))						/* node that user want to insert BEFORE is found */
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Finished, node [%d] was inserted", apstTempNode->uiListNo);
#endif
				wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]++;			/* Node No increased */		/* 2012/11/06 Fixed by Tianyufang */
				wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]++;			/* Node Num increased */	/* 2012/11/06 Fixed by Tianyufang */
				apstNodeData					=	(wstSglLinkedList *)MEM_ALLOC(sizeof(wstSglLinkedList));			/* alloc memory for point of Node */
				apstNodeData->vpDataContainer	=	(DSF_USERDEF_LIST_DATA *)MEM_ALLOC(sizeof(DSF_USERDEF_LIST_DATA));	/* alloc memory for point of user data */
				apstNodeData->uiListNo			=	wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_MAX][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];									/* 2012/11/06 Fixed by Tianyufang */
				
				(void)memcpy(apstNodeData->vpDataContainer, pstNodeData, sizeof(DSF_USERDEF_LIST_DATA));				/* return data that will be Insert */


				/*---- Comment ----*/	/* 2012/10/30 Fixed by Tianyufang */
				/* the possibility of node's position that you want to insert BEFORE was shown below 
				No	Node Num  Insert Node   Root Node    Last Node     New Node     New Node->Next    Node Total Number
				1	 >= 1        Root         New        Do Nothing      Root           Root               N + 1
				2     > 1        Last       Do Nothing   Do Nothing    aLast->Next      Last               N + 1
				3     > 1        Middle     Do Nothing   Do Nothing    aLast->Next  TempNode->Next         N + 1*/
				if (pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] == apstTempNode)			/* process for 1 */	/* 2012/11/06 Fixed by Tianyufang */
				{
					pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] = apstNodeData;			/* New Node become Root Node */	/* 2012/11/06 Fixed by Tianyufang */
					apstNodeData->pstNext = apstTempNode;														/* New Node become Last Root Node */
				}
				else if (pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] == apstTempNode)	/* process for 2 */	/* 2012/11/06 Fixed by Tianyufang */
				{
					apstLastNode->pstNext = apstNodeData;														/* next node's point of last node point to New Node */
					apstNodeData->pstNext = pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];	/* next node's point of new node point to point of last node */	/* 2012/11/06 Fixed by Tianyufang */
				}
				else																							/* process for 3 */
				{
					apstLastNode->pstNext = apstNodeData;														/* next node's point of last node point to New Node */
					apstNodeData->pstNext = apstTempNode;														/* next node's point of new node point to point of last node */
				}
				/* 2012/10/30 Fixed by Tianyufang */
				aubRslt	= DSF_OPRT_OK;
				break;
			}
			else
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Continue, Now is %d Node!", apstTempNode->uiListNo);
#endif
				apstLastNode = apstTempNode;
				apstTempNode = apstTempNode->pstNext;
				if (NULL == apstTempNode->pstNext)
				{
					break;
				}
			}
		}while(NULL != apstTempNode);
	}

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wubSglLinkedListModifyNode                                                       *
*  Version No    : Ver 002                                                                         *
*  Description   : Modify Linked List Node and Return Data of this node                            *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/10/26                                                                      *
*  Modify Date   : 2012/11/06                                                                      *
*  Parament      : BOOL(*pfUserModProc)(DSF_USERDEF_LIST_DATA *)  : User define function for Seek  *
*                : DSF_USERDEF_LIST_DATA                          : node data for insert           *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/10/26  New                                                                 *
*  2   Tianyufang  2012/11/06  Change Globle variables to array                                    *
*                                                                                                  *
*==================================================================================================*/
uByte wubSglLinkedListModifyNode(BOOL (*pfUserModProc)(DSF_USERDEF_LIST_DATA *), DSF_USERDEF_LIST_DATA *pstNodeData)
{
	wstSglLinkedList *apstTempNode;
	uByte aubRslt;

	aubRslt	= DSF_OPRT_NG;												/* local variable initlize */
	apstTempNode	= NULL;
	
	if (NULL != pfUserModProc)											/* whether user defined function is available */
	{
		apstTempNode = pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];					/* point of node for pointing to current node pointed to Root node */	/* 2012/11/06 Fixed by Tianyufang */

		do
		{
			if (NULL == pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]])					/* whether none node had been created */	/* 2012/11/06 Fixed by Tianyufang */
			{
				break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tNone Node Exited!");
#endif
			}
			if (TRUE == (*pfUserModProc)((DSF_USERDEF_LIST_DATA *)apstTempNode->vpDataContainer))			/* node that user want to delete is found */
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Finished, node [%d] was modify", apstTempNode->uiListNo);
#endif
				(void)memcpy(apstTempNode->vpDataContainer, pstNodeData, sizeof(DSF_USERDEF_LIST_DATA));	/* return data that will be deleted */

				aubRslt	= DSF_OPRT_OK;
				break;
			}
			else
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Continue, Now is %d Node!", apstTempNode->uiListNo);
#endif
				apstTempNode = apstTempNode->pstNext;
			}
		}while(NULL != apstTempNode);
	}

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wubSglLinkedListGetNode                                                          *
*  Version No    : Ver 002                                                                         *
*  Description   : Delete Linked List Node and Return Data of this node                            *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/10/11                                                                      *
*  Modify Date   : 2012/11/06                                                                      *
*  Parament      : uiNodeID                          : Node ID that User request                   *
*                : DSF_USERDEF_LIST_DATA **          : point of node data that request             *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/10/11  New                                                                 *
*  2   Tianyufang  2012/11/06  Change Globle variables to array                                    *
*                                                                                                  *
*==================================================================================================*/
uByte wubSglLinkedListGetNode(uInt uiNodeID, DSF_USERDEF_LIST_DATA **pstNodeData)
{
	wstSglLinkedList *apstTempNode;
	uByte aubRslt;

	aubRslt	= DSF_OPRT_NG;
	apstTempNode	= NULL;

	apstTempNode = pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];		/* 2012/11/06 Fixed by Tianyufang */

	do
	{
		if (NULL == pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]])		/* 2012/11/06 Fixed by Tianyufang */
		{
			break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tNone Node Exited!");
#endif
		}
		if (uiNodeID == apstTempNode->uiListNo)
		{
#if PROMPT_MESSAGE_ON
OUTPUT_MSG("\n\tGet Node Data Finished, node [%d] was get", apstTempNode->uiListNo);
#endif
			pstNodeData = (DSF_USERDEF_LIST_DATA **)apstTempNode->vpDataContainer;
			aubRslt	= DSF_OPRT_OK;
			break;
		}
		else
		{
#if PROMPT_MESSAGE_ON
OUTPUT_MSG("\n\tGet Node Data Continue, Now is %d Node!", apstTempNode->uiListNo);
#endif
			apstTempNode = apstTempNode->pstNext;
		}
	}while(NULL != apstTempNode);

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wstSglLinkedListGetNode                                                          *
*  Version No    : Ver 002                                                                         *
*  Description   : return total number of the linked list                                          *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/10/11                                                                      *
*  Modify Date   : 2012/11/06                                                                      *
*  Parament      : None                                                                            *
*  Return Value  : uByte              : number of total node                                       *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/10/11  New                                                                 *
*  2   Tianyufang  2012/11/06  Change Globle variables to array                                    *
*                                                                                                  *
*==================================================================================================*/
uInt wuiSglLinkedListGetNodeTotalNum(void)
{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tTotal Node Num : [%d]", wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]);		/* 2012/11/06 Fixed by Tianyufang */
#endif
	return wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];											/* 2012/11/06 Fixed by Tianyufang */
}
#endif

#ifdef DOUBLY_LINKED_LIST
/***************************************************************************************************
*  Function Name : wubDblLinkedListInitProc                                                        *
*  Version No    : Ver 001                                                                         *
*  Description   : Initialize Global Variables(DSF and user define) Process Function               *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2013/01/09                                                                      *
*  Modify Date   : 2013/01/09                                                                      *
*  Parament      : void(*pfUserInitProc)(void)           :initialize process for user define       *
*                : uWord ListNo                          :linked list No                           *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2013/01/09  New                                                                 *
*                                                                                                  *
*==================================================================================================*/
uByte wubDblLinkedListInitProc(void (*pfUserInitProc)(void), uWord ListNo)
{
	uByte aubRslt;

	aubRslt = DSF_OPRT_NG;
	
	if (DSF_OPRT_OK == wvdLinkedListSetNoProc(ListNo, DSF_LINKED_LIST_TYPE_DOUBLE))		/* Assigned Which Linked List user want to initlize */
	{
		wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_DOUBLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]	=	0;
		wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_DOUBLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]	=	0;
		pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]	=	NULL;
		pstDSFDblLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]	=	NULL;

#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tDSF Var Init Finished\t");
#endif
	
		if (NULL != pfUserInitProc)														/* execute user initlize function */
		{
			(void)(*pfUserInitProc)();
			aubRslt = DSF_OPRT_OK;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tUser Var Init Finished\t");
#endif
		}
	}
	else
	{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tDSF Linked List Initlized out of range\t");
#endif
	}

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wubDblLinkedListCreatNode                                                       *
*  Version No    : Ver 001                                                                         *
*  Description   : Creat Linked List Node and allocate the memory for node                         *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2013/01/09                                                                      *
*  Modify Date   : 2013/01/09                                                                      *
*  Parament      : DSF_USERDEF_LIST_DATA **             : point of user defined data type          *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2013/01/09  New                                                                 *
*                                                                                                  *
*==================================================================================================*/
uByte wubDblLinkedListCreatNode(DSF_USERDEF_LIST_DATA **pstDSFNode)
{
	wstDblLinkedList *apstDSFTempNode;
	uByte aubRslt;
	
	apstDSFTempNode = NULL;									/* local variables initlize */
	aubRslt = DSF_OPRT_NG;
	
	wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_DOUBLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]++;				/* Node No increased */
	apstDSFTempNode						=	(wstDblLinkedList *)MEM_ALLOC(sizeof(wstDblLinkedList));			/* alloc memory for point of Node */
	apstDSFTempNode->vpDataContainer	=	(DSF_USERDEF_LIST_DATA *)MEM_ALLOC(sizeof(DSF_USERDEF_LIST_DATA));	/* alloc memory for point of user data */
	apstDSFTempNode->uiListNo			=	wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_DOUBLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]];
	apstDSFTempNode->pstHead			=	NULL;
	apstDSFTempNode->pstTail			=	NULL;

	if ((NULL != apstDSFTempNode) && (NULL != apstDSFTempNode->vpDataContainer))								/* make sure that memory alloc successed */
	{
		wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_DOUBLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]++;			/* Node Num increased */
		pstDSFNode = (DSF_USERDEF_LIST_DATA **)apstDSFTempNode->vpDataContainer;								/* return user data address */
		memset(pstDSFNode, 0x00, sizeof(DSF_USERDEF_LIST_DATA));
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tCurrent Node Created,Address: 0x%08X,No:[%d]", apstDSFTempNode, wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_DOUBLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]);
#endif
		if ((uInt)(1) == wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_DOUBLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]])
		{
			pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]] = apstDSFTempNode;				/* Root node created */
			pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]->pstHead = pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]];	/* Head Pointer point to itself */
			pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]->pstTail = pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]];	/* Tail Pointer point to itself */
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tRoot Node Created,Address: 0x%08X,No:[%d]", pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]], wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]);
	OUTPUT_MSG("\n\tRoot Node Created,Head Address: 0x%08X", pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]->pstHead);
	OUTPUT_MSG("\n\tRoot Node Created,Tail Address: 0x%08X", pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]->pstTail);
#endif
		}
		else
		{
			pstDSFDblLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]->pstTail = apstDSFTempNode;		/* Tail Pointer point to next node */
			apstDSFTempNode->pstHead = pstDSFDblLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]];		/* Head pointer of Next Node point to Last Node */
		}
		pstDSFDblLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]] = apstDSFTempNode;					/* move point of last node */
		aubRslt = DSF_OPRT_OK;
	}
	else
	{
		wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_DOUBLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]--;			/* memory alloc for node failed, Node No decrease */
	}

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wubDblLinkedListSeekNode                                                        *
*  Version No    : Ver 001                                                                         *
*  Description   : Seek Linked List Node return the address of this node                           *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2013/01/09                                                                      *
*  Modify Date   : 2013/01/09                                                                      *
*  Parament      : BOOL(*pfUserInitProc)(DSF_USERDEF_LIST_DATA *) : User define function for seek  *
*                : DSF_USERDEF_LIST_DATA **                       : point of user seeked Node      *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2013/01/09  New                                                                 *
*                                                                                                  *
*==================================================================================================*/
uByte wubDblLinkedListSeekNode(BOOL (*pfUserSeekProc)(DSF_USERDEF_LIST_DATA *), DSF_USERDEF_LIST_DATA **pstNodeData)
{
	wstDblLinkedList *apstTempNode;
	uByte aubRslt;

	aubRslt = DSF_OPRT_NG;											/* local variable initlize */
	apstTempNode = NULL;
	pstNodeData = (DSF_USERDEF_LIST_DATA **)NULL;

	if (NULL != pfUserSeekProc)										/* whether user defined function is available */
	{
		apstTempNode = pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]];				/* seek for Root node */
		do
		{
			if (NULL != pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]])				/* whether none node had been created */
			{
				break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tNone Node Exited!");
#endif
			}

			if (TRUE == (*pfUserSeekProc)((DSF_USERDEF_LIST_DATA *)apstTempNode->vpDataContainer))		/* user seek data is found */
			{
				pstNodeData	=	(DSF_USERDEF_LIST_DATA **)apstTempNode->vpDataContainer;				/* return address that user request */
				aubRslt		=	DSF_OPRT_OK;
				break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Finished, This is %d node", apstTempNode->uiListNo);
#endif
			}
			else
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Continue, Now is %d Node!", apstTempNode->uiListNo);
#endif
				apstTempNode = apstTempNode->pstTail;													/* user request data does not match, node point is movd to next */
			}
		}while(NULL != apstTempNode);
	}

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wubDblLinkedListDeleteNode                                                      *
*  Version No    : Ver 001                                                                         *
*  Description   : Delete Linked List Node and Return Data of this node                            *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2013/01/09                                                                      *
*  Modify Date   : 2013/01/09                                                                      *
*  Parament      : BOOL(*pfUserInitProc)(DSF_USERDEF_LIST_DATA *) : User define function for seek  *
*                : DSF_USERDEF_LIST_DATA *                        : point of node data that delete *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2013/01/09  New                                                                 *
*                                                                                                  *
*==================================================================================================*/
uByte wubDblLinkedListDeleteNode(BOOL (*pfUserDelProc)(DSF_USERDEF_LIST_DATA *), DSF_USERDEF_LIST_DATA *pstNodeData)
{
	wstDblLinkedList *apstTempNode;
	uByte aubRslt;

	aubRslt	= DSF_OPRT_NG;												/* local variable initlize */
	apstTempNode	= NULL;
	
	if (NULL != pfUserDelProc)											/* whether user defined function is available */
	{
		apstTempNode = pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]];				/* point of node for pointing to current node pointed to Root node */	/* 2012/11/06 Fixed by Tianyufang */

		do
		{
			if (NULL == pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]])				/* whether none node had been created */
			{
				break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tNone Node Exited");
#endif
			}
			if (TRUE == (*pfUserDelProc)((DSF_USERDEF_LIST_DATA *)apstTempNode->vpDataContainer))		/* node that user want to delete is found */
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Finished, node [%d] was deleted", apstTempNode->uiListNo);
#endif
				/*---- Comment ----*/
				/* the possibility of node's position that you want to delete was shown below 
				No	Node Number   Will Delete Node      Root Node       Last Node       Node Total Number
				1	     1              Root               NULL            NULL                0
				2        > 1            Root            Root->Next       Do Nothing          N - 1
				3        > 1            Last            Do Nothing      Node(Last)->Next     N - 1
				4        > 1            Middle          Do Nothing       Do Nothing          N - 1*/
				if (pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]] == apstTempNode)
				{
					if (NULL == apstTempNode->pstTail)						/* process for 1 */
					{
						pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]->pstHead = NULL;
						pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]->pstTail = NULL;
						pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]] = NULL;
						pstDSFDblLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]->pstHead = NULL;
						pstDSFDblLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]->pstTail = NULL;
						pstDSFDblLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]] = NULL;
					}
					else													/* process for 2 */
					{
						pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]]->pstTail = apstTempNode->pstTail;	/* Root Node's Tail pointer point to Node's Tail pointer which will be deleted */
						apstTempNode->pstTail->pstHead = pstDSFDblRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]];	/* Head pointer of Node's Tail pointer which will be deleted point to Root point */
					}
				}
				else if (pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]] == apstTempNode)				/* process for 3 */
				{
					pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_DOUBLE]] = apstLastNode;
				}
				else														/* process for 4 */
				{
					apstLastNode->pstNext = apstTempNode->pstNext;
				}

				(void)memcpy(pstNodeData, apstTempNode->vpDataContainer, sizeof(DSF_USERDEF_LIST_DATA));	/* return data that will be deleted */
				FREE(apstTempNode->vpDataContainer);														/* release memory for data of current node */
				FREE(apstTempNode);																			/* release memory for node of current node */
				wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]--;
				aubRslt	= DSF_OPRT_OK;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tDelete Finished, [%d] node(s) remains", wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]);
#endif

				break;
			}
			else
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Continue, Now is %d Node!", apstTempNode->uiListNo);
#endif
				apstLastNode = apstTempNode;
				apstTempNode = apstTempNode->pstNext;
			}
		}while(NULL != apstTempNode);
	}

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wubSlgLinkedListInsertNode                                                      *
*  Version No    : Ver 002                                                                         *
*  Description   : Insert Linked List Node and pass Data for this node                             *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/10/26                                                                      *
*  Modify Date   : 2012/11/06                                                                      *
*  Parament      : BOOL(*pfUserModProc)(DSF_USERDEF_LIST_DATA *)  : User define function for Seek  *
*                : DSF_USERDEF_LIST_DATA                          : node data for insert           *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/10/26  New                                                                 *
*  2   Tianyufang  2012/11/06  Change Globle variables to array                                    *
*                                                                                                  *
*==================================================================================================*/
uByte wubSlgLinkedListInsertNode(BOOL (*pfUserInsProc)(DSF_USERDEF_LIST_DATA *), DSF_USERDEF_LIST_DATA *pstNodeData)
{
	wstSglLinkedList *apstTempNode, *apstLastNode, *apstNodeData;
	uByte aubRslt;

	aubRslt	= DSF_OPRT_NG;												/* local variable initlize */
	apstTempNode	= NULL;
	apstLastNode	= NULL;
	apstNodeData	= NULL;
	
	if (NULL != pfUserInsProc)											/* whether user defined function is available */
	{
		apstTempNode = pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];				/* point of node for pointing to current node pointed to Root node */	/* 2012/11/06 Fixed by Tianyufang */
		apstLastNode = pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];				/* point of node for pointing to last node pointed to Root node */	/* 2012/11/06 Fixed by Tianyufang */

		do
		{
			if (NULL == pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]])				/* whether none node had been created */	/* 2012/11/06 Fixed by Tianyufang */
			{
				break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tNone Node Exited!");
#endif
			}
			if (TRUE == (*pfUserInsProc)((DSF_USERDEF_LIST_DATA *)apstTempNode->vpDataContainer))						/* node that user want to insert BEFORE is found */
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Finished, node [%d] was inserted", apstTempNode->uiListNo);
#endif
				wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]++;			/* Node No increased */		/* 2012/11/06 Fixed by Tianyufang */
				wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]++;			/* Node Num increased */	/* 2012/11/06 Fixed by Tianyufang */
				apstNodeData					=	(wstSglLinkedList *)MEM_ALLOC(sizeof(wstSglLinkedList));			/* alloc memory for point of Node */
				apstNodeData->vpDataContainer	=	(DSF_USERDEF_LIST_DATA *)MEM_ALLOC(sizeof(DSF_USERDEF_LIST_DATA));	/* alloc memory for point of user data */
				apstNodeData->uiListNo			=	wuiDSFNodeNo[DSF_LINKED_LIST_TYPE_MAX][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];									/* 2012/11/06 Fixed by Tianyufang */
				
				(void)memcpy(apstNodeData->vpDataContainer, pstNodeData, sizeof(DSF_USERDEF_LIST_DATA));				/* return data that will be Insert */


				/*---- Comment ----*/	/* 2012/10/30 Fixed by Tianyufang */
				/* the possibility of node's position that you want to insert BEFORE was shown below 
				No	Node Num  Insert Node   Root Node    Last Node     New Node     New Node->Next    Node Total Number
				1	 >= 1        Root         New        Do Nothing      Root           Root               N + 1
				2     > 1        Last       Do Nothing   Do Nothing    aLast->Next      Last               N + 1
				3     > 1        Middle     Do Nothing   Do Nothing    aLast->Next  TempNode->Next         N + 1*/
				if (pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] == apstTempNode)			/* process for 1 */	/* 2012/11/06 Fixed by Tianyufang */
				{
					pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] = apstNodeData;			/* New Node become Root Node */	/* 2012/11/06 Fixed by Tianyufang */
					apstNodeData->pstNext = apstTempNode;														/* New Node become Last Root Node */
				}
				else if (pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]] == apstTempNode)	/* process for 2 */	/* 2012/11/06 Fixed by Tianyufang */
				{
					apstLastNode->pstNext = apstNodeData;														/* next node's point of last node point to New Node */
					apstNodeData->pstNext = pstDSFSglLastNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];	/* next node's point of new node point to point of last node */	/* 2012/11/06 Fixed by Tianyufang */
				}
				else																							/* process for 3 */
				{
					apstLastNode->pstNext = apstNodeData;														/* next node's point of last node point to New Node */
					apstNodeData->pstNext = apstTempNode;														/* next node's point of new node point to point of last node */
				}
				/* 2012/10/30 Fixed by Tianyufang */
				aubRslt	= DSF_OPRT_OK;
				break;
			}
			else
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Continue, Now is %d Node!", apstTempNode->uiListNo);
#endif
				apstLastNode = apstTempNode;
				apstTempNode = apstTempNode->pstNext;
				if (NULL == apstTempNode->pstNext)
				{
					break;
				}
			}
		}while(NULL != apstTempNode);
	}

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wubSlgLinkedListModifyNode                                                       *
*  Version No    : Ver 002                                                                         *
*  Description   : Modify Linked List Node and Return Data of this node                            *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/10/26                                                                      *
*  Modify Date   : 2012/11/06                                                                      *
*  Parament      : BOOL(*pfUserModProc)(DSF_USERDEF_LIST_DATA *)  : User define function for Seek  *
*                : DSF_USERDEF_LIST_DATA                          : node data for insert           *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/10/26  New                                                                 *
*  2   Tianyufang  2012/11/06  Change Globle variables to array                                    *
*                                                                                                  *
*==================================================================================================*/
uByte wubSlgLinkedListModifyNode(BOOL (*pfUserModProc)(DSF_USERDEF_LIST_DATA *), DSF_USERDEF_LIST_DATA *pstNodeData)
{
	wstSglLinkedList *apstTempNode;
	uByte aubRslt;

	aubRslt	= DSF_OPRT_NG;												/* local variable initlize */
	apstTempNode	= NULL;
	
	if (NULL != pfUserModProc)											/* whether user defined function is available */
	{
		apstTempNode = pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];					/* point of node for pointing to current node pointed to Root node */	/* 2012/11/06 Fixed by Tianyufang */

		do
		{
			if (NULL == pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]])					/* whether none node had been created */	/* 2012/11/06 Fixed by Tianyufang */
			{
				break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tNone Node Exited!");
#endif
			}
			if (TRUE == (*pfUserModProc)((DSF_USERDEF_LIST_DATA *)apstTempNode->vpDataContainer))			/* node that user want to delete is found */
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Finished, node [%d] was modify", apstTempNode->uiListNo);
#endif
				(void)memcpy(apstTempNode->vpDataContainer, pstNodeData, sizeof(DSF_USERDEF_LIST_DATA));	/* return data that will be deleted */

				aubRslt	= DSF_OPRT_OK;
				break;
			}
			else
			{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tSeek Continue, Now is %d Node!", apstTempNode->uiListNo);
#endif
				apstTempNode = apstTempNode->pstNext;
			}
		}while(NULL != apstTempNode);
	}

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wubSlgLinkedListGetNode                                                          *
*  Version No    : Ver 002                                                                         *
*  Description   : Delete Linked List Node and Return Data of this node                            *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/10/11                                                                      *
*  Modify Date   : 2012/11/06                                                                      *
*  Parament      : uiNodeID                          : Node ID that User request                   *
*                : DSF_USERDEF_LIST_DATA **          : point of node data that request             *
*  Return Value  : uByte              : DSF_OPRT_OK:Data available  DSF_OPRT_NG:Data unavaiable    *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/10/11  New                                                                 *
*  2   Tianyufang  2012/11/06  Change Globle variables to array                                    *
*                                                                                                  *
*==================================================================================================*/
uByte wubSlgLinkedListGetNode(uInt uiNodeID, DSF_USERDEF_LIST_DATA **pstNodeData)
{
	wstSglLinkedList *apstTempNode;
	uByte aubRslt;

	aubRslt	= DSF_OPRT_NG;
	apstTempNode	= NULL;

	apstTempNode = pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];		/* 2012/11/06 Fixed by Tianyufang */

	do
	{
		if (NULL == pstDSFSglRootNode[wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]])		/* 2012/11/06 Fixed by Tianyufang */
		{
			break;
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tNone Node Exited!");
#endif
		}
		if (uiNodeID == apstTempNode->uiListNo)
		{
#if PROMPT_MESSAGE_ON
OUTPUT_MSG("\n\tGet Node Data Finished, node [%d] was get", apstTempNode->uiListNo);
#endif
			pstNodeData = (DSF_USERDEF_LIST_DATA **)apstTempNode->vpDataContainer;
			aubRslt	= DSF_OPRT_OK;
			break;
		}
		else
		{
#if PROMPT_MESSAGE_ON
OUTPUT_MSG("\n\tGet Node Data Continue, Now is %d Node!", apstTempNode->uiListNo);
#endif
			apstTempNode = apstTempNode->pstNext;
		}
	}while(NULL != apstTempNode);

	return aubRslt;
}

/***************************************************************************************************
*  Function Name : wstSlgLinkedListGetNode                                                          *
*  Version No    : Ver 002                                                                         *
*  Description   : return total number of the linked list                                          *
*  Author        : Tianyufang                                                                      *
*  Creat Date    : 2012/10/11                                                                      *
*  Modify Date   : 2012/11/06                                                                      *
*  Parament      : None                                                                            *
*  Return Value  : uByte              : number of total node                                       *
*==================================================================================================*
*  No  Name        Date        Modify Content                                                      *
*  1   Tianyufang  2012/10/11  New                                                                 *
*  2   Tianyufang  2012/11/06  Change Globle variables to array                                    *
*                                                                                                  *
*==================================================================================================*/
uInt wuiSlgLinkedListGetNodeTotalNum(void)
{
#if PROMPT_MESSAGE_ON
	OUTPUT_MSG("\n\tTotal Node Num : [%d]", wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]]);		/* 2012/11/06 Fixed by Tianyufang */
#endif
	return wuiDSFNodeNum[DSF_LINKED_LIST_TYPE_SINGLE][wuwDSFLinkedListNo[DSF_LINKED_LIST_TYPE_SINGLE]];											/* 2012/11/06 Fixed by Tianyufang */
}
#endif

